package eg;

import java.util.ArrayList;
import java.util.List;

public class PlayerList {

    private List<Player> players = new ArrayList<Player>();

    public void add(Player player) {
        players.add(player);
    }

    public int getCountPlayers() {
        return players.size();
    }

    public Player[] getPlayers() {
        Player[] result = new Player[players.size()];
        players.toArray(result);
        return result;
    }

    public void reset() {
        players.clear();
    }

    public Player getPlayerByName(String name) {
        Player[] result = getPlayers();
        for (int i = 0; i < result.length; i++) {
            if ((result[i].getName() != null)
                    && (result[i].getName().equals(name))) {
                return result[i];
            }
        }
        return null;
    }
    
    public Player getPlayerById(int id) {
        return players.get(id);
    }

}
